package com.ieasy.module.oa.project.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.ieasy.basic.dao.IBaseDao;
import com.ieasy.basic.exception.ServiceException;
import com.ieasy.basic.model.DataGrid;
import com.ieasy.basic.model.Msg;
import com.ieasy.basic.model.Pager;
import com.ieasy.basic.util.BeanUtils;
import com.ieasy.basic.util.NumberUtil;
import com.ieasy.module.common.service.BaseService;
import com.ieasy.module.oa.project.entity.ForecastEntity;
import com.ieasy.module.oa.project.entity.ForecastYearEntity;
import com.ieasy.module.oa.project.entity.PersonBudget;
import com.ieasy.module.oa.project.web.form.ComapnyMemberCountForm;
import com.ieasy.module.oa.project.web.form.ForecastForm;
import com.ieasy.module.oa.project.web.form.PersonBudgetForm;

@Service
@Transactional
public class ForecastService extends BaseService implements IForecastService {
	
	@Inject
	private IBaseDao<ForecastEntity> basedaoForecast;
	
	@Inject
	private IBaseDao<ForecastYearEntity> basedaoForecastYear;
	
	@Inject
	private IComapnyMemberCountService comapnyMemberCountService ;
	
	@Inject
	private IBaseDao<PersonBudget> basedaoPersonBudget;

	@Override
	public Msg add(ForecastForm form) {
		ForecastEntity newEntity = new ForecastEntity() ;
		BeanUtils.copyNotNullProperties(form, newEntity);
		
		newEntity.setCreated(new Date());
		newEntity.setCreateName(super.getCurrentUser().getEmp_name());
		ForecastEntity add = this.basedaoForecast.add(newEntity) ;
		
		ForecastYearEntity fyEntity = new ForecastYearEntity() ;
		BeanUtils.copyNotNullProperties(form, fyEntity);
		fyEntity.setForecastId(add.getId());
		fyEntity.setCreated(new Date());
		fyEntity.setCreateName(super.getCurrentUser().getEmp_name());
		this.basedaoForecastYear.add(fyEntity) ;
		
		
		return new Msg(true, "提交成功！") ;
	}
	
	@Override
	public Msg update(ForecastForm form) {
		ForecastEntity entity = this.basedaoForecast.load(ForecastEntity.class, form.getId());
		BeanUtils.copyNotNullProperties(form, entity);
		this.basedaoForecast.update(entity);
		
		ForecastForm byYear = this.getByYear(form) ;
		
		if(null != byYear.getId()) {
			String forecastMonthId = byYear.getId() ;
			
			BeanUtils.copyNotNullProperties(form, byYear, new String[]{"id"});
			byYear.setId(forecastMonthId);
			byYear.setForecastId(form.getId());
			
			ForecastYearEntity fyEntity = new ForecastYearEntity() ;
			BeanUtils.copyNotNullProperties(byYear, fyEntity);
			
			fyEntity.setModifyDate(new Date());
			fyEntity.setModifyName(super.getCurrentUser().getEmp_name());
			this.basedaoForecastYear.update(fyEntity);
		} else {
			ForecastYearEntity fyEntity = new ForecastYearEntity() ;
			BeanUtils.copyNotNullProperties(form, fyEntity, new String[]{"id"});
			fyEntity.setForecastId(form.getId());
			
			fyEntity.setModifyDate(new Date());
			fyEntity.setModifyName(super.getCurrentUser().getEmp_name());
			this.basedaoForecastYear.add(fyEntity);
		}
		
		return new Msg(true, "修改成功！") ;
	}
	
	@Override
	public Msg delete(ForecastForm form) {
		try {
			if(null != form.getIds() && !"".equals(form.getIds())) {
				String[] ids = form.getIds().split(",") ;
				for (String id : ids) {
					ForecastEntity entity = this.basedaoForecast.load(ForecastEntity.class, id) ;
					this.basedaoForecast.delete(entity) ;
				}
				return new Msg(true, "删除成功！") ;
			}
		} catch (Exception e) {
			return new Msg(false, "删除失败！") ;
		}
		return null;
	}
	
	@Override
	public ForecastForm get(ForecastForm form) {
		try {
			String sql = "select " 
					+ "t.*, "
					+ "ty.year, "
					+ "ty.jp_down_m1,ty.jp_down_m10,ty.jp_down_m11,ty.jp_down_m12,ty.jp_down_m2,ty.jp_down_m3,"
					+ "ty.jp_down_m4,ty.jp_down_m5,ty.jp_down_m6,ty.jp_down_m7,ty.jp_down_m8,ty.jp_down_m9,"
					+ "ty.jp_up_m1,ty.jp_up_m10,ty.jp_up_m11,ty.jp_up_m12,ty.jp_up_m2,ty.jp_up_m3,ty.jp_up_m4,"
					+ "ty.jp_up_m5,ty.jp_up_m6,ty.jp_up_m7,ty.jp_up_m8,ty.jp_up_m9,ty.zh_down_m1,ty.zh_down_m10,"
					+ "ty.zh_down_m11,ty.zh_down_m12,ty.zh_down_m2,ty.zh_down_m3,ty.zh_down_m4,ty.zh_down_m5,ty.zh_down_m6,"
					+ "ty.zh_down_m7,ty.zh_down_m8,ty.zh_down_m9,ty.zh_up_m1,ty.zh_up_m10,ty.zh_up_m11,"
					+ "ty.zh_up_m12,ty.zh_up_m2,ty.zh_up_m3,ty.zh_up_m4,ty.zh_up_m5,ty.zh_up_m6,ty.zh_up_m7,ty.zh_up_m8,ty.zh_up_m9 "+
					"from ieasy_oa_forecast t " +
					"JOIN ieasy_oa_forecast_year ty ON(ty.forecastId=t.id) " +
					"where t.id='"+form.getId()+"' and ty.year='"+form.getYear()+"'";
			ForecastForm f = (ForecastForm)this.basedaoForecast.queryObjectSQL(sql, ForecastForm.class, false) ;
			
			
			return f ;
		} catch (Exception e) {
			e.printStackTrace() ;
			throw new ServiceException("加载信息异常：", e) ;
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> forecast_report(ForecastForm form) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>() ;
		
		Map<String, Object> m1 = new HashMap<String, Object>() ;
		m1.put("category", "部門预订人数（人）") ;
		Map<String, Object> m2 = new HashMap<String, Object>() ;
		m2.put("category", "最大需求人数（人）") ;
		Map<String, Object> m3 = new HashMap<String, Object>() ;
		m3.put("category", "最小需求人数（人）") ;
		
		Map<String, Object> m4 = new HashMap<String, Object>() ;
		m4.put("category", "需求平均（人）") ;
		Map<String, Object> m5 = new HashMap<String, Object>() ;
		m5.put("category", "最大空闲人数（人）") ;
		Map<String, Object> m6 = new HashMap<String, Object>() ;
		m6.put("category", "最小空闲人数（人）") ;
		Map<String, Object> m7 = new HashMap<String, Object>() ;
		m7.put("category", "空闲平均（人）") ;
		
		Map<String, Object> m11 = new HashMap<String, Object>() ;
		m11.put("category", "WZN全社合計人数（人）") ;
		
		
		//各地区在职人数(广州开发在职总人数/苏州开发在职总人数/北京开发在职总人数)
		ComapnyMemberCountForm cf = new ComapnyMemberCountForm() ;
		cf.setSearchYear(form.getYear());
		DataGrid dagagrid = this.comapnyMemberCountService.dagagrid(cf) ;
		List<Map<String, Object>> rows = (List<Map<String, Object>>) dagagrid.getRows() ;
		float t1 = 0,t2 = 0,t3 = 0,t4 = 0,t5 = 0,t6 = 0,t7 = 0,t8 = 0,t9 = 0,t10 = 0,t11 = 0,t12 = 0;
		for(int i=0; i< rows.size(); i++) {
			Map<String, Object> m = rows.get(i) ;
			list.add(m);
			
			t1+=m.get("m1")==null?0:Float.parseFloat(m.get("m1").toString());
			t2+=m.get("m2")==null?0:Float.parseFloat(m.get("m2").toString());
			t3+=m.get("m3")==null?0:Float.parseFloat(m.get("m3").toString());
			t4+=m.get("m4")==null?0:Float.parseFloat(m.get("m4").toString());
			t5+=m.get("m5")==null?0:Float.parseFloat(m.get("m5").toString());
			t6+=m.get("m6")==null?0:Float.parseFloat(m.get("m6").toString());
			t7+=m.get("m7")==null?0:Float.parseFloat(m.get("m7").toString());
			t8+=m.get("m8")==null?0:Float.parseFloat(m.get("m8").toString());
			t9+=m.get("m9")==null?0:Float.parseFloat(m.get("m9").toString());
			t10+=m.get("m10")==null?0:Float.parseFloat(m.get("m10").toString());
			t11+=m.get("m11")==null?0:Float.parseFloat(m.get("m11").toString());
			t12+=m.get("m12")==null?0:Float.parseFloat(m.get("m12").toString());
		}
		m11.put("m1", t1);
		m11.put("m2", t2);
		m11.put("m3", t3);
		m11.put("m4", t4);
		m11.put("m5", t5);
		m11.put("m6", t6);
		m11.put("m7", t7);
		m11.put("m8", t8);
		m11.put("m9", t9);
		m11.put("m10", t10);
		m11.put("m11", t11);
		m11.put("m12", t12);
		
		list.add(m11) ;
		
		//部門预订人数（人）
		String sqlTotal = 
				"select b.category, "+ 
				"sum(b.m1) as tm1, sum(b.m2) as tm2, sum(b.m3) as tm3, sum(b.m4) as tm4, sum(b.m5) as tm5, "+
				"sum(b.m6) as tm6, sum(b.m7) as tm7, sum(b.m8) as tm8, sum(b.m9) as tm9, sum(b.m10) as tm10, "+
				"sum(b.m11) as tm11, sum(b.m12) as tm12 "+
				"FROM ieasy_oa_person_budget b WHERE b.year=? and b.category='deptCount'";
		PersonBudgetForm pbf = (PersonBudgetForm) this.basedaoPersonBudget.queryObjectSQL(sqlTotal, new Object[]{form.getYear()}, PersonBudgetForm.class, false);
		if(null != pbf) {
			m1.put("m1", pbf.getTm1()==null?0:pbf.getTm1());
			m1.put("m2", pbf.getTm2()==null?0:pbf.getTm2());
			m1.put("m3", pbf.getTm3()==null?0:pbf.getTm3());
			m1.put("m4", pbf.getTm4()==null?0:pbf.getTm4());
			m1.put("m5", pbf.getTm5()==null?0:pbf.getTm5());
			m1.put("m6", pbf.getTm6()==null?0:pbf.getTm6());
			m1.put("m7", pbf.getTm7()==null?0:pbf.getTm7());
			m1.put("m8", pbf.getTm8()==null?0:pbf.getTm8());
			m1.put("m9", pbf.getTm9()==null?0:pbf.getTm9());
			m1.put("m10", pbf.getTm10()==null?0:pbf.getTm10());
			m1.put("m11", pbf.getTm11()==null?0:pbf.getTm11());
			m1.put("m12", pbf.getTm12()==null?0:pbf.getTm12());
		}
		
		//最大需求人数（人）
		ForecastForm forecast_total_up_avg = this.forecast_total_up_avg(form) ;
		m2.put("m1", forecast_total_up_avg.getM1());
		m2.put("m2", forecast_total_up_avg.getM2());
		m2.put("m3", forecast_total_up_avg.getM3());
		m2.put("m4", forecast_total_up_avg.getM4());
		m2.put("m5", forecast_total_up_avg.getM5());
		m2.put("m6", forecast_total_up_avg.getM6());
		m2.put("m7", forecast_total_up_avg.getM7());
		m2.put("m8", forecast_total_up_avg.getM8());
		m2.put("m9", forecast_total_up_avg.getM9());
		m2.put("m10", forecast_total_up_avg.getM10());
		m2.put("m11", forecast_total_up_avg.getM11());
		m2.put("m12", forecast_total_up_avg.getM12());
		
		
		//最小需求人数（人）
		ForecastForm forecast_total_down_avg = this.forecast_total_down_avg(form) ;
		m3.put("m1", forecast_total_down_avg.getM1());
		m3.put("m2", forecast_total_down_avg.getM2());
		m3.put("m3", forecast_total_down_avg.getM3());
		m3.put("m4", forecast_total_down_avg.getM4());
		m3.put("m5", forecast_total_down_avg.getM5());
		m3.put("m6", forecast_total_down_avg.getM6());
		m3.put("m7", forecast_total_down_avg.getM7());
		m3.put("m8", forecast_total_down_avg.getM8());
		m3.put("m9", forecast_total_down_avg.getM9());
		m3.put("m10", forecast_total_down_avg.getM10());
		m3.put("m11", forecast_total_down_avg.getM11());
		m3.put("m12", forecast_total_down_avg.getM12());
		
		
		//计算需求平均（人）(部門预订人数（人）+最小需求人数（人）)/2
		m4.put("m1", NumberUtil.setScale((Float.parseFloat(m2.get("m1").toString())+Float.parseFloat(m3.get("m1").toString()))/2));
		m4.put("m2", NumberUtil.setScale((Float.parseFloat(m2.get("m2").toString())+Float.parseFloat(m3.get("m2").toString()))/2));
		m4.put("m3", NumberUtil.setScale((Float.parseFloat(m2.get("m3").toString())+Float.parseFloat(m3.get("m3").toString()))/2));
		m4.put("m4", NumberUtil.setScale((Float.parseFloat(m2.get("m4").toString())+Float.parseFloat(m3.get("m4").toString()))/2));
		m4.put("m5", NumberUtil.setScale((Float.parseFloat(m2.get("m5").toString())+Float.parseFloat(m3.get("m5").toString()))/2));
		m4.put("m6", NumberUtil.setScale((Float.parseFloat(m2.get("m6").toString())+Float.parseFloat(m3.get("m6").toString()))/2));
		m4.put("m7", NumberUtil.setScale((Float.parseFloat(m2.get("m7").toString())+Float.parseFloat(m3.get("m7").toString()))/2));
		m4.put("m8", NumberUtil.setScale((Float.parseFloat(m2.get("m8").toString())+Float.parseFloat(m3.get("m8").toString()))/2));
		m4.put("m9", NumberUtil.setScale((Float.parseFloat(m2.get("m9").toString())+Float.parseFloat(m3.get("m9").toString()))/2));
		m4.put("m10", NumberUtil.setScale((Float.parseFloat(m2.get("m10").toString())+Float.parseFloat(m3.get("m10").toString()))/2));
		m4.put("m11", NumberUtil.setScale((Float.parseFloat(m2.get("m11").toString())+Float.parseFloat(m3.get("m11").toString()))/2));
		m4.put("m12", NumberUtil.setScale((Float.parseFloat(m2.get("m12").toString())+Float.parseFloat(m3.get("m12").toString()))/2));
		
		//最大空闲人数（人）
		m5.put("m1", NumberUtil.setScale((Float.parseFloat(m11.get("m1").toString())-Float.parseFloat(m3.get("m1").toString()))));
		m5.put("m2", NumberUtil.setScale((Float.parseFloat(m11.get("m2").toString())-Float.parseFloat(m3.get("m2").toString()))));
		m5.put("m3", NumberUtil.setScale((Float.parseFloat(m11.get("m3").toString())-Float.parseFloat(m3.get("m3").toString()))));
		m5.put("m4", NumberUtil.setScale((Float.parseFloat(m11.get("m4").toString())-Float.parseFloat(m3.get("m4").toString()))));
		m5.put("m5", NumberUtil.setScale((Float.parseFloat(m11.get("m5").toString())-Float.parseFloat(m3.get("m5").toString()))));
		m5.put("m6", NumberUtil.setScale((Float.parseFloat(m11.get("m6").toString())-Float.parseFloat(m3.get("m6").toString()))));
		m5.put("m7", NumberUtil.setScale((Float.parseFloat(m11.get("m7").toString())-Float.parseFloat(m3.get("m7").toString()))));
		m5.put("m8", NumberUtil.setScale((Float.parseFloat(m11.get("m8").toString())-Float.parseFloat(m3.get("m8").toString()))));
		m5.put("m9", NumberUtil.setScale((Float.parseFloat(m11.get("m9").toString())-Float.parseFloat(m3.get("m9").toString()))));
		m5.put("m10", NumberUtil.setScale((Float.parseFloat(m11.get("m10").toString())-Float.parseFloat(m3.get("m10").toString()))));
		m5.put("m11", NumberUtil.setScale((Float.parseFloat(m11.get("m11").toString())-Float.parseFloat(m3.get("m11").toString()))));
		m5.put("m12", NumberUtil.setScale((Float.parseFloat(m11.get("m12").toString())-Float.parseFloat(m3.get("m12").toString()))));
		
		//最小空闲人数（人）
		m6.put("m1", NumberUtil.setScale((Float.parseFloat(m11.get("m1").toString())-Float.parseFloat(m2.get("m1").toString()))));
		m6.put("m2", NumberUtil.setScale((Float.parseFloat(m11.get("m2").toString())-Float.parseFloat(m2.get("m2").toString()))));
		m6.put("m3", NumberUtil.setScale((Float.parseFloat(m11.get("m3").toString())-Float.parseFloat(m2.get("m3").toString()))));
		m6.put("m4", NumberUtil.setScale((Float.parseFloat(m11.get("m4").toString())-Float.parseFloat(m2.get("m4").toString()))));
		m6.put("m5", NumberUtil.setScale((Float.parseFloat(m11.get("m5").toString())-Float.parseFloat(m2.get("m5").toString()))));
		m6.put("m6", NumberUtil.setScale((Float.parseFloat(m11.get("m6").toString())-Float.parseFloat(m2.get("m6").toString()))));
		m6.put("m7", NumberUtil.setScale((Float.parseFloat(m11.get("m7").toString())-Float.parseFloat(m2.get("m7").toString()))));
		m6.put("m8", NumberUtil.setScale((Float.parseFloat(m11.get("m8").toString())-Float.parseFloat(m2.get("m8").toString()))));
		m6.put("m9", NumberUtil.setScale((Float.parseFloat(m11.get("m9").toString())-Float.parseFloat(m2.get("m9").toString()))));
		m6.put("m10", NumberUtil.setScale((Float.parseFloat(m11.get("m10").toString())-Float.parseFloat(m2.get("m10").toString()))));
		m6.put("m11", NumberUtil.setScale((Float.parseFloat(m11.get("m11").toString())-Float.parseFloat(m2.get("m11").toString()))));
		m6.put("m12", NumberUtil.setScale((Float.parseFloat(m11.get("m12").toString())-Float.parseFloat(m2.get("m12").toString()))));
		
		//空闲平均（人）
		m7.put("m1", NumberUtil.setScale((Float.parseFloat(m5.get("m1").toString())+Float.parseFloat(m6.get("m1").toString()))/2));
		m7.put("m2", NumberUtil.setScale((Float.parseFloat(m5.get("m2").toString())+Float.parseFloat(m6.get("m2").toString()))/2));
		m7.put("m3", NumberUtil.setScale((Float.parseFloat(m5.get("m3").toString())+Float.parseFloat(m6.get("m3").toString()))/2));
		m7.put("m4", NumberUtil.setScale((Float.parseFloat(m5.get("m4").toString())+Float.parseFloat(m6.get("m4").toString()))/2));
		m7.put("m5", NumberUtil.setScale((Float.parseFloat(m5.get("m5").toString())+Float.parseFloat(m6.get("m5").toString()))/2));
		m7.put("m6", NumberUtil.setScale((Float.parseFloat(m5.get("m6").toString())+Float.parseFloat(m6.get("m6").toString()))/2));
		m7.put("m7", NumberUtil.setScale((Float.parseFloat(m5.get("m7").toString())+Float.parseFloat(m6.get("m7").toString()))/2));
		m7.put("m8", NumberUtil.setScale((Float.parseFloat(m5.get("m8").toString())+Float.parseFloat(m6.get("m8").toString()))/2));
		m7.put("m9", NumberUtil.setScale((Float.parseFloat(m5.get("m9").toString())+Float.parseFloat(m6.get("m9").toString()))/2));
		m7.put("m10", NumberUtil.setScale((Float.parseFloat(m5.get("m10").toString())+Float.parseFloat(m6.get("m10").toString()))/2));
		m7.put("m11", NumberUtil.setScale((Float.parseFloat(m5.get("m11").toString())+Float.parseFloat(m6.get("m11").toString()))/2));
		m7.put("m12", NumberUtil.setScale((Float.parseFloat(m5.get("m12").toString())+Float.parseFloat(m6.get("m12").toString()))/2));
		
		list.add(m1) ;
		list.add(m2) ;
		list.add(m3) ;
		
		list.add(m4) ;
		list.add(m5) ;
		list.add(m6) ;
		list.add(m7) ;
		
		return list ;
	}
	
	public ForecastForm forecast_total_up_avg(ForecastForm form) {
		ForecastForm total = new ForecastForm() ;
		List<ForecastForm> redureTotalGroupUp = redureTotalGroupUp(form) ;
		for (ForecastForm ff : redureTotalGroupUp) {
			total.setM1(total.getM1()+ff.getM1());
			total.setM2(total.getM2()+ff.getM2());
			total.setM3(total.getM3()+ff.getM3());
			total.setM4(total.getM4()+ff.getM4());
			total.setM5(total.getM5()+ff.getM5());
			total.setM6(total.getM6()+ff.getM6());
			total.setM7(total.getM7()+ff.getM7());
			total.setM8(total.getM8()+ff.getM8());
			total.setM9(total.getM9()+ff.getM9());
			total.setM10(total.getM10()+ff.getM10());
			total.setM11(total.getM11()+ff.getM11());
			total.setM12(total.getM12()+ff.getM12());
		}
		
		return total ;
	}
	
	public ForecastForm forecast_total_down_avg(ForecastForm form) {
		ForecastForm total = new ForecastForm() ;
		List<ForecastForm> redureTotalGroupDown = redureTotalGroupDown(form) ;
		for (ForecastForm ff : redureTotalGroupDown) {
			total.setM1(total.getM1()+ff.getM1());
			total.setM2(total.getM2()+ff.getM2());
			total.setM3(total.getM3()+ff.getM3());
			total.setM4(total.getM4()+ff.getM4());
			total.setM5(total.getM5()+ff.getM5());
			total.setM6(total.getM6()+ff.getM6());
			total.setM7(total.getM7()+ff.getM7());
			total.setM8(total.getM8()+ff.getM8());
			total.setM9(total.getM9()+ff.getM9());
			total.setM10(total.getM10()+ff.getM10());
			total.setM11(total.getM11()+ff.getM11());
			total.setM12(total.getM12()+ff.getM12());
		}
		
		return total ;
	}
	
	@Override
	public List<ForecastForm> forecast_total_up(ForecastForm form) {
		ForecastForm total = new ForecastForm() ;
		total.setCustCategory("合计");
		
		List<ForecastForm> redureTotalGroup = redureTotalGroupUp(form) ;
		for (ForecastForm ff : redureTotalGroup) {
			total.setM1(total.getM1()+ff.getM1());
			total.setM2(total.getM2()+ff.getM2());
			total.setM3(total.getM3()+ff.getM3());
			total.setM4(total.getM4()+ff.getM4());
			total.setM5(total.getM5()+ff.getM5());
			total.setM6(total.getM6()+ff.getM6());
			total.setM7(total.getM7()+ff.getM7());
			total.setM8(total.getM8()+ff.getM8());
			total.setM9(total.getM9()+ff.getM9());
			total.setM10(total.getM10()+ff.getM10());
			total.setM11(total.getM11()+ff.getM11());
			total.setM12(total.getM12()+ff.getM12());
		}
		
		redureTotalGroup.add(total);
		
		
		return redureTotalGroup;
	}
	private List<ForecastForm> redureTotalGroupUp(ForecastForm form) {
		Map<String, Object> alias = new HashMap<String, Object>(); 
		String sql = "SELECT "
				+"t.custCategory,"
				+"("
				+"	select round(SUM((tc.jp_up_m1+tc.zh_up_m1+tc.jp_down_m1+tc.zh_down_m1)/2)) "
				+"	from ieasy_oa_forecast_year tc "
				+"	JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"	where "
				+"		tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm1',"
				+"("
				+"		select round(SUM((tc.jp_up_m2+tc.zh_up_m2+tc.jp_down_m2+tc.zh_down_m2)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm2',"
				+"("
				+"		select round(SUM((tc.jp_up_m3+tc.zh_up_m3+tc.jp_down_m3+tc.zh_down_m3)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm3',"
				+"("
				+"		select round(SUM((tc.jp_up_m4+tc.zh_up_m4+tc.jp_down_m4+tc.zh_down_m4)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm4',"
				+"("
				+"		select round(SUM((tc.jp_up_m5+tc.zh_up_m5+tc.jp_down_m5+tc.zh_down_m5)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm5',"
				+"("
				+"		select round(SUM((tc.jp_up_m6+tc.zh_up_m6+tc.jp_down_m6+tc.zh_down_m6)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm6',"
				+"("
				+"		select round(SUM((tc.jp_up_m7+tc.zh_up_m7+tc.jp_down_m7+tc.zh_down_m7)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm7',"
				+"("
				+"		select round(SUM((tc.jp_up_m8+tc.zh_up_m8+tc.jp_down_m8+tc.zh_down_m8)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm8',"
				+"("
				+"		select round(SUM((tc.jp_up_m9+tc.zh_up_m9+tc.jp_down_m9+tc.zh_down_m9)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm9',"
				+"("
				+"		select round(SUM((tc.jp_up_m10+tc.zh_up_m10+tc.jp_down_m10+tc.zh_down_m10)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm10',"
				+"("
				+"		select round(SUM((tc.jp_up_m11+tc.zh_up_m11+tc.jp_down_m11+tc.zh_down_m11)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm11',"
				+"("
				+"		select round(SUM((tc.jp_up_m12+tc.zh_up_m12+tc.jp_down_m12+tc.zh_down_m12)/2)) "
				+"		from ieasy_oa_forecast_year tc "
				+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
				+"		where "
				+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory"
				+") as 'm12'"
				+"from ieasy_oa_forecast t "
				+"JOIN ieasy_oa_forecast_year ty ON(ty.forecastId=t.id) "
				+"where "
				+"	ty.year = "+form.getYear()+" "
				+"	GROUP BY t.custCategory" ;
		
		
		return this.basedaoForecast.listSQL(sql, alias, ForecastForm.class, false) ;
	}
	
	@Override
	public List<ForecastForm> forecast_total_down(ForecastForm form) {
		ForecastForm total = new ForecastForm() ;
		total.setCustCategory("合计");
		
		List<ForecastForm> redureTotalGroup = redureTotalGroupDown(form) ;
		for (ForecastForm ff : redureTotalGroup) {
			total.setM1(total.getM1()+ff.getM1());
			total.setM2(total.getM2()+ff.getM2());
			total.setM3(total.getM3()+ff.getM3());
			total.setM4(total.getM4()+ff.getM4());
			total.setM5(total.getM5()+ff.getM5());
			total.setM6(total.getM6()+ff.getM6());
			total.setM7(total.getM7()+ff.getM7());
			total.setM8(total.getM8()+ff.getM8());
			total.setM9(total.getM9()+ff.getM9());
			total.setM10(total.getM10()+ff.getM10());
			total.setM11(total.getM11()+ff.getM11());
			total.setM12(total.getM12()+ff.getM12());
		}
		
		redureTotalGroup.add(total);
		
		
		return redureTotalGroup;
	}
	private List<ForecastForm> redureTotalGroupDown(ForecastForm form) {
		Map<String, Object> alias = new HashMap<String, Object>(); 
		String sql = "SELECT "
						+"t.custCategory,"
						+"("
						+"	select round(SUM((tc.jp_up_m1+tc.zh_up_m1+tc.jp_down_m1+tc.zh_down_m1)/2)) "
						+"	from ieasy_oa_forecast_year tc "
						+"	JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"	where "
						+"		tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100 "
						+") as 'm1',"
						+"("
						+"		select round(SUM((tc.jp_up_m2+tc.zh_up_m2+tc.jp_down_m2+tc.zh_down_m2)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm2',"
						+"("
						+"		select round(SUM((tc.jp_up_m3+tc.zh_up_m3+tc.jp_down_m3+tc.zh_down_m3)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm3',"
						+"("
						+"		select round(SUM((tc.jp_up_m4+tc.zh_up_m4+tc.jp_down_m4+tc.zh_down_m4)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm4',"
						+"("
						+"		select round(SUM((tc.jp_up_m5+tc.zh_up_m5+tc.jp_down_m5+tc.zh_down_m5)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm5',"
						+"("
						+"		select round(SUM((tc.jp_up_m6+tc.zh_up_m6+tc.jp_down_m6+tc.zh_down_m6)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm6',"
						+"("
						+"		select round(SUM((tc.jp_up_m7+tc.zh_up_m7+tc.jp_down_m7+tc.zh_down_m7)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm7',"
						+"("
						+"		select round(SUM((tc.jp_up_m8+tc.zh_up_m8+tc.jp_down_m8+tc.zh_down_m8)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm8',"
						+"("
						+"		select round(SUM((tc.jp_up_m9+tc.zh_up_m9+tc.jp_down_m9+tc.zh_down_m9)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm9',"
						+"("
						+"		select round(SUM((tc.jp_up_m10+tc.zh_up_m10+tc.jp_down_m10+tc.zh_down_m10)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm10',"
						+"("
						+"		select round(SUM((tc.jp_up_m11+tc.zh_up_m11+tc.jp_down_m11+tc.zh_down_m11)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm11',"
						+"("
						+"		select round(SUM((tc.jp_up_m12+tc.zh_up_m12+tc.jp_down_m12+tc.zh_down_m12)/2)) "
						+"		from ieasy_oa_forecast_year tc "
						+"		JOIN ieasy_oa_forecast tt ON(tc.forecastId=tt.id) "
						+"		where "
						+"			tc.year = "+form.getYear()+" AND tt.custCategory=t.custCategory and tt.projDegree=100"
						+") as 'm12'"
					+"from ieasy_oa_forecast t "
					+"JOIN ieasy_oa_forecast_year ty ON(ty.forecastId=t.id) "
					+"where "
					+"	ty.year = "+form.getYear()+" AND t.projDegree=100 "
					+"	GROUP BY t.custCategory" ;
		
		
		return this.basedaoForecast.listSQL(sql, alias, ForecastForm.class, false) ;
	}
	
	@Override
	public ForecastForm getByYear(ForecastForm form) {
		try {
			String sql = "select "
					 + "ty.id,"
					 + "ty.forecastId,"
					 + "ty.year,"
					 + "ty.jp_down_m1,ty.jp_down_m10,ty.jp_down_m11,ty.jp_down_m12,ty.jp_down_m2,ty.jp_down_m3,"
					 + "ty.jp_down_m4,ty.jp_down_m5,ty.jp_down_m6,ty.jp_down_m7,ty.jp_down_m8,ty.jp_down_m9,"
					 + "ty.jp_up_m1,ty.jp_up_m10,ty.jp_up_m11,ty.jp_up_m12,ty.jp_up_m2,ty.jp_up_m3,ty.jp_up_m4,"
					 + "ty.jp_up_m5,ty.jp_up_m6,ty.jp_up_m7,ty.jp_up_m8,ty.jp_up_m9,ty.zh_down_m1,ty.zh_down_m10,"
					 + "ty.zh_down_m11,ty.zh_down_m12,ty.zh_down_m2,ty.zh_down_m3,ty.zh_down_m4,ty.zh_down_m5,ty."
					 + "zh_down_m6,ty.zh_down_m7,ty.zh_down_m8,ty.zh_down_m9,ty.zh_up_m1,ty.zh_up_m10,ty.zh_up_m11,"
					 + "ty.zh_up_m12,ty.zh_up_m2,ty.zh_up_m3,ty.zh_up_m4,ty.zh_up_m5,ty.zh_up_m6,ty.zh_up_m7,ty.zh_up_m8,ty.zh_up_m9 "+
					 "from ieasy_oa_forecast_year ty " +
				 	 "where ty.forecastId='"+form.getId()+"' and ty.year='"+form.getYear()+"'";
			
			ForecastForm f = (ForecastForm)this.basedaoForecastYear.queryObjectSQL(sql, ForecastForm.class, false) ;
			
			if(null == f) {
				f = new ForecastForm() ;
				f.setYear(form.getYear());
				return f ;
			}
			return f ;
		} catch (Exception e) {
			e.printStackTrace() ;
			throw new ServiceException("加载信息异常：", e) ;
		}
	}

	
	
	private DataGrid redure(List<ForecastForm> findList) {
	
		
		List<Map<String, Object>> footers = new ArrayList<Map<String, Object>>();
		
		Map<String, Object> footerMap1 = new HashMap<String, Object>() ;
		Map<String, Object> footerMap2 = new HashMap<String, Object>() ;
		Map<String, Object> footerMap3 = new HashMap<String, Object>() ;
		Map<String, Object> footerMap4 = new HashMap<String, Object>() ;
		footerMap1.put("pm", "<b>小计</b>");
		footerMap2.put("pm", "<b>合计</b>");
		footerMap3.put("pm", "<b>上旬</b>");
		footerMap4.put("pm", "<b>下旬</b>");
		
		if(null != findList && !findList.isEmpty()) {
			/**
			 * PJ完了：YES的是隐藏
			 */
			for (ForecastForm forecastForm : findList) {
				if(forecastForm.getProjOver().equals("NO")) {
					//小计
					footerMap1.put("zh_up_m1", (footerMap1.get("zh_up_m1")==null?forecastForm.getZh_down_m1():Float.parseFloat(footerMap1.get("zh_up_m1").toString())+forecastForm.getZh_up_m1()));
					footerMap1.put("zh_down_m1", (footerMap1.get("zh_down_m1")==null?forecastForm.getZh_down_m1():Float.parseFloat(footerMap1.get("zh_down_m1").toString())+forecastForm.getZh_down_m1()));
					footerMap1.put("jp_up_m1", (footerMap1.get("jp_up_m1")==null?forecastForm.getJp_up_m1():Float.parseFloat(footerMap1.get("jp_up_m1").toString())+forecastForm.getJp_up_m1()));
					footerMap1.put("jp_down_m1", (footerMap1.get("jp_down_m1")==null?forecastForm.getJp_down_m1():Float.parseFloat(footerMap1.get("jp_down_m1").toString())+forecastForm.getJp_down_m1()));
					
					footerMap1.put("zh_up_m2", (footerMap1.get("zh_up_m2")==null?forecastForm.getZh_down_m2():Float.parseFloat(footerMap1.get("zh_up_m2").toString())+forecastForm.getZh_up_m2()));
					footerMap1.put("zh_down_m2", (footerMap1.get("zh_down_m2")==null?forecastForm.getZh_down_m2():Float.parseFloat(footerMap1.get("zh_down_m2").toString())+forecastForm.getZh_down_m2()));
					footerMap1.put("jp_up_m2", (footerMap1.get("jp_up_m2")==null?forecastForm.getJp_up_m2():Float.parseFloat(footerMap1.get("jp_up_m2").toString())+forecastForm.getJp_up_m2()));
					footerMap1.put("jp_down_m2", (footerMap1.get("jp_down_m2")==null?forecastForm.getJp_down_m2():Float.parseFloat(footerMap1.get("jp_down_m2").toString())+forecastForm.getJp_down_m2()));
					
					footerMap1.put("zh_up_m3", (footerMap1.get("zh_up_m3")==null?forecastForm.getZh_down_m3():Float.parseFloat(footerMap1.get("zh_up_m3").toString())+forecastForm.getZh_up_m3()));
					footerMap1.put("zh_down_m3", (footerMap1.get("zh_down_m3")==null?forecastForm.getZh_down_m3():Float.parseFloat(footerMap1.get("zh_down_m3").toString())+forecastForm.getZh_down_m3()));
					footerMap1.put("jp_up_m3", (footerMap1.get("jp_up_m3")==null?forecastForm.getJp_up_m3():Float.parseFloat(footerMap1.get("jp_up_m3").toString())+forecastForm.getJp_up_m3()));
					footerMap1.put("jp_down_m3", (footerMap1.get("jp_down_m3")==null?forecastForm.getJp_down_m3():Float.parseFloat(footerMap1.get("jp_down_m3").toString())+forecastForm.getJp_down_m3()));
					
					footerMap1.put("zh_up_m4", (footerMap1.get("zh_up_m4")==null?forecastForm.getZh_down_m4():Float.parseFloat(footerMap1.get("zh_up_m4").toString())+forecastForm.getZh_up_m4()));
					footerMap1.put("zh_down_m4", (footerMap1.get("zh_down_m4")==null?forecastForm.getZh_down_m4():Float.parseFloat(footerMap1.get("zh_down_m4").toString())+forecastForm.getZh_down_m4()));
					footerMap1.put("jp_up_m4", (footerMap1.get("jp_up_m4")==null?forecastForm.getJp_up_m4():Float.parseFloat(footerMap1.get("jp_up_m4").toString())+forecastForm.getJp_up_m4()));
					footerMap1.put("jp_down_m4", (footerMap1.get("jp_down_m4")==null?forecastForm.getJp_down_m4():Float.parseFloat(footerMap1.get("jp_down_m4").toString())+forecastForm.getJp_down_m4()));
					
					footerMap1.put("zh_up_m5", (footerMap1.get("zh_up_m5")==null?forecastForm.getZh_down_m5():Float.parseFloat(footerMap1.get("zh_up_m5").toString())+forecastForm.getZh_up_m5()));
					footerMap1.put("zh_down_m5", (footerMap1.get("zh_down_m5")==null?forecastForm.getZh_down_m5():Float.parseFloat(footerMap1.get("zh_down_m5").toString())+forecastForm.getZh_down_m5()));
					footerMap1.put("jp_up_m5", (footerMap1.get("jp_up_m5")==null?forecastForm.getJp_up_m5():Float.parseFloat(footerMap1.get("jp_up_m5").toString())+forecastForm.getJp_up_m5()));
					footerMap1.put("jp_down_m5", (footerMap1.get("jp_down_m5")==null?forecastForm.getJp_down_m5():Float.parseFloat(footerMap1.get("jp_down_m5").toString())+forecastForm.getJp_down_m5()));
					
					footerMap1.put("zh_up_m6", (footerMap1.get("zh_up_m6")==null?forecastForm.getZh_down_m6():Float.parseFloat(footerMap1.get("zh_up_m6").toString())+forecastForm.getZh_up_m6()));
					footerMap1.put("zh_down_m6", (footerMap1.get("zh_down_m6")==null?forecastForm.getZh_down_m6():Float.parseFloat(footerMap1.get("zh_down_m6").toString())+forecastForm.getZh_down_m6()));
					footerMap1.put("jp_up_m6", (footerMap1.get("jp_up_m6")==null?forecastForm.getJp_up_m6():Float.parseFloat(footerMap1.get("jp_up_m6").toString())+forecastForm.getJp_up_m6()));
					footerMap1.put("jp_down_m6", (footerMap1.get("jp_down_m6")==null?forecastForm.getJp_down_m6():Float.parseFloat(footerMap1.get("jp_down_m6").toString())+forecastForm.getJp_down_m6()));
					
					footerMap1.put("zh_up_m7", (footerMap1.get("zh_up_m7")==null?forecastForm.getZh_down_m7():Float.parseFloat(footerMap1.get("zh_up_m7").toString())+forecastForm.getZh_up_m7()));
					footerMap1.put("zh_down_m7", (footerMap1.get("zh_down_m7")==null?forecastForm.getZh_down_m7():Float.parseFloat(footerMap1.get("zh_down_m7").toString())+forecastForm.getZh_down_m7()));
					footerMap1.put("jp_up_m7", (footerMap1.get("jp_up_m7")==null?forecastForm.getJp_up_m7():Float.parseFloat(footerMap1.get("jp_up_m7").toString())+forecastForm.getJp_up_m7()));
					footerMap1.put("jp_down_m7", (footerMap1.get("jp_down_m7")==null?forecastForm.getJp_down_m7():Float.parseFloat(footerMap1.get("jp_down_m7").toString())+forecastForm.getJp_down_m7()));
					
					footerMap1.put("zh_up_m8", (footerMap1.get("zh_up_m8")==null?forecastForm.getZh_down_m8():Float.parseFloat(footerMap1.get("zh_up_m8").toString())+forecastForm.getZh_up_m8()));
					footerMap1.put("zh_down_m8", (footerMap1.get("zh_down_m8")==null?forecastForm.getZh_down_m8():Float.parseFloat(footerMap1.get("zh_down_m8").toString())+forecastForm.getZh_down_m8()));
					footerMap1.put("jp_up_m8", (footerMap1.get("jp_up_m8")==null?forecastForm.getJp_up_m8():Float.parseFloat(footerMap1.get("jp_up_m8").toString())+forecastForm.getJp_up_m8()));
					footerMap1.put("jp_down_m8", (footerMap1.get("jp_down_m8")==null?forecastForm.getJp_down_m8():Float.parseFloat(footerMap1.get("jp_down_m8").toString())+forecastForm.getJp_down_m8()));
					
					footerMap1.put("zh_up_m9", (footerMap1.get("zh_up_m9")==null?forecastForm.getZh_down_m9():Float.parseFloat(footerMap1.get("zh_up_m9").toString())+forecastForm.getZh_up_m9()));
					footerMap1.put("zh_down_m9", (footerMap1.get("zh_down_m9")==null?forecastForm.getZh_down_m9():Float.parseFloat(footerMap1.get("zh_down_m9").toString())+forecastForm.getZh_down_m9()));
					footerMap1.put("jp_up_m9", (footerMap1.get("jp_up_m9")==null?forecastForm.getJp_up_m9():Float.parseFloat(footerMap1.get("jp_up_m9").toString())+forecastForm.getJp_up_m9()));
					footerMap1.put("jp_down_m9", (footerMap1.get("jp_down_m9")==null?forecastForm.getJp_down_m9():Float.parseFloat(footerMap1.get("jp_down_m9").toString())+forecastForm.getJp_down_m9()));
					
					footerMap1.put("zh_up_m10", (footerMap1.get("zh_up_m10")==null?forecastForm.getZh_down_m10():Float.parseFloat(footerMap1.get("zh_up_m10").toString())+forecastForm.getZh_up_m10()));
					footerMap1.put("zh_down_m10", (footerMap1.get("zh_down_m10")==null?forecastForm.getZh_down_m10():Float.parseFloat(footerMap1.get("zh_down_m10").toString())+forecastForm.getZh_down_m10()));
					footerMap1.put("jp_up_m10", (footerMap1.get("jp_up_m10")==null?forecastForm.getJp_up_m10():Float.parseFloat(footerMap1.get("jp_up_m10").toString())+forecastForm.getJp_up_m10()));
					footerMap1.put("jp_down_m10", (footerMap1.get("jp_down_m10")==null?forecastForm.getJp_down_m10():Float.parseFloat(footerMap1.get("jp_down_m10").toString())+forecastForm.getJp_down_m10()));
					
					footerMap1.put("zh_up_m11", (footerMap1.get("zh_up_m11")==null?forecastForm.getZh_down_m11():Float.parseFloat(footerMap1.get("zh_up_m11").toString())+forecastForm.getZh_up_m11()));
					footerMap1.put("zh_down_m11", (footerMap1.get("zh_down_m11")==null?forecastForm.getZh_down_m11():Float.parseFloat(footerMap1.get("zh_down_m11").toString())+forecastForm.getZh_down_m11()));
					footerMap1.put("jp_up_m11", (footerMap1.get("jp_up_m11")==null?forecastForm.getJp_up_m11():Float.parseFloat(footerMap1.get("jp_up_m11").toString())+forecastForm.getJp_up_m11()));
					footerMap1.put("jp_down_m11", (footerMap1.get("jp_down_m11")==null?forecastForm.getJp_down_m11():Float.parseFloat(footerMap1.get("jp_down_m11").toString())+forecastForm.getJp_down_m11()));
					
					footerMap1.put("zh_up_m12", (footerMap1.get("zh_up_m12")==null?forecastForm.getZh_down_m12():Float.parseFloat(footerMap1.get("zh_up_m12").toString())+forecastForm.getZh_up_m12()));
					footerMap1.put("zh_down_m12", (footerMap1.get("zh_down_m12")==null?forecastForm.getZh_down_m12():Float.parseFloat(footerMap1.get("zh_down_m12").toString())+forecastForm.getZh_down_m12()));
					footerMap1.put("jp_up_m12", (footerMap1.get("jp_up_m12")==null?forecastForm.getJp_up_m12():Float.parseFloat(footerMap1.get("jp_up_m12").toString())+forecastForm.getJp_up_m12()));
					footerMap1.put("jp_down_m12", (footerMap1.get("jp_down_m12")==null?forecastForm.getJp_down_m12():Float.parseFloat(footerMap1.get("jp_down_m12").toString())+forecastForm.getJp_down_m12()));
				}  else {
					//小计
					footerMap1.put("zh_up_m1", (footerMap1.get("zh_up_m1")==null?forecastForm.getZh_down_m1():Float.parseFloat(footerMap1.get("zh_up_m1").toString())+forecastForm.getZh_up_m1()));
					footerMap1.put("zh_down_m1", (footerMap1.get("zh_down_m1")==null?forecastForm.getZh_down_m1():Float.parseFloat(footerMap1.get("zh_down_m1").toString())+forecastForm.getZh_down_m1()));
					footerMap1.put("jp_up_m1", (footerMap1.get("jp_up_m1")==null?forecastForm.getJp_up_m1():Float.parseFloat(footerMap1.get("jp_up_m1").toString())+forecastForm.getJp_up_m1()));
					footerMap1.put("jp_down_m1", (footerMap1.get("jp_down_m1")==null?forecastForm.getJp_down_m1():Float.parseFloat(footerMap1.get("jp_down_m1").toString())+forecastForm.getJp_down_m1()));
					
					footerMap1.put("zh_up_m2", (footerMap1.get("zh_up_m2")==null?forecastForm.getZh_down_m2():Float.parseFloat(footerMap1.get("zh_up_m2").toString())+forecastForm.getZh_up_m2()));
					footerMap1.put("zh_down_m2", (footerMap1.get("zh_down_m2")==null?forecastForm.getZh_down_m2():Float.parseFloat(footerMap1.get("zh_down_m2").toString())+forecastForm.getZh_down_m2()));
					footerMap1.put("jp_up_m2", (footerMap1.get("jp_up_m2")==null?forecastForm.getJp_up_m2():Float.parseFloat(footerMap1.get("jp_up_m2").toString())+forecastForm.getJp_up_m2()));
					footerMap1.put("jp_down_m2", (footerMap1.get("jp_down_m2")==null?forecastForm.getJp_down_m2():Float.parseFloat(footerMap1.get("jp_down_m2").toString())+forecastForm.getJp_down_m2()));
					
					footerMap1.put("zh_up_m3", (footerMap1.get("zh_up_m3")==null?forecastForm.getZh_down_m3():Float.parseFloat(footerMap1.get("zh_up_m3").toString())+forecastForm.getZh_up_m3()));
					footerMap1.put("zh_down_m3", (footerMap1.get("zh_down_m3")==null?forecastForm.getZh_down_m3():Float.parseFloat(footerMap1.get("zh_down_m3").toString())+forecastForm.getZh_down_m3()));
					footerMap1.put("jp_up_m3", (footerMap1.get("jp_up_m3")==null?forecastForm.getJp_up_m3():Float.parseFloat(footerMap1.get("jp_up_m3").toString())+forecastForm.getJp_up_m3()));
					footerMap1.put("jp_down_m3", (footerMap1.get("jp_down_m3")==null?forecastForm.getJp_down_m3():Float.parseFloat(footerMap1.get("jp_down_m3").toString())+forecastForm.getJp_down_m3()));
					
					footerMap1.put("zh_up_m4", (footerMap1.get("zh_up_m4")==null?forecastForm.getZh_down_m4():Float.parseFloat(footerMap1.get("zh_up_m4").toString())+forecastForm.getZh_up_m4()));
					footerMap1.put("zh_down_m4", (footerMap1.get("zh_down_m4")==null?forecastForm.getZh_down_m4():Float.parseFloat(footerMap1.get("zh_down_m4").toString())+forecastForm.getZh_down_m4()));
					footerMap1.put("jp_up_m4", (footerMap1.get("jp_up_m4")==null?forecastForm.getJp_up_m4():Float.parseFloat(footerMap1.get("jp_up_m4").toString())+forecastForm.getJp_up_m4()));
					footerMap1.put("jp_down_m4", (footerMap1.get("jp_down_m4")==null?forecastForm.getJp_down_m4():Float.parseFloat(footerMap1.get("jp_down_m4").toString())+forecastForm.getJp_down_m4()));
					
					footerMap1.put("zh_up_m5", (footerMap1.get("zh_up_m5")==null?forecastForm.getZh_down_m5():Float.parseFloat(footerMap1.get("zh_up_m5").toString())+forecastForm.getZh_up_m5()));
					footerMap1.put("zh_down_m5", (footerMap1.get("zh_down_m5")==null?forecastForm.getZh_down_m5():Float.parseFloat(footerMap1.get("zh_down_m5").toString())+forecastForm.getZh_down_m5()));
					footerMap1.put("jp_up_m5", (footerMap1.get("jp_up_m5")==null?forecastForm.getJp_up_m5():Float.parseFloat(footerMap1.get("jp_up_m5").toString())+forecastForm.getJp_up_m5()));
					footerMap1.put("jp_down_m5", (footerMap1.get("jp_down_m5")==null?forecastForm.getJp_down_m5():Float.parseFloat(footerMap1.get("jp_down_m5").toString())+forecastForm.getJp_down_m5()));
					
					footerMap1.put("zh_up_m6", (footerMap1.get("zh_up_m6")==null?forecastForm.getZh_down_m6():Float.parseFloat(footerMap1.get("zh_up_m6").toString())+forecastForm.getZh_up_m6()));
					footerMap1.put("zh_down_m6", (footerMap1.get("zh_down_m6")==null?forecastForm.getZh_down_m6():Float.parseFloat(footerMap1.get("zh_down_m6").toString())+forecastForm.getZh_down_m6()));
					footerMap1.put("jp_up_m6", (footerMap1.get("jp_up_m6")==null?forecastForm.getJp_up_m6():Float.parseFloat(footerMap1.get("jp_up_m6").toString())+forecastForm.getJp_up_m6()));
					footerMap1.put("jp_down_m6", (footerMap1.get("jp_down_m6")==null?forecastForm.getJp_down_m6():Float.parseFloat(footerMap1.get("jp_down_m6").toString())+forecastForm.getJp_down_m6()));
					
					footerMap1.put("zh_up_m7", (footerMap1.get("zh_up_m7")==null?forecastForm.getZh_down_m7():Float.parseFloat(footerMap1.get("zh_up_m7").toString())+forecastForm.getZh_up_m7()));
					footerMap1.put("zh_down_m7", (footerMap1.get("zh_down_m7")==null?forecastForm.getZh_down_m7():Float.parseFloat(footerMap1.get("zh_down_m7").toString())+forecastForm.getZh_down_m7()));
					footerMap1.put("jp_up_m7", (footerMap1.get("jp_up_m7")==null?forecastForm.getJp_up_m7():Float.parseFloat(footerMap1.get("jp_up_m7").toString())+forecastForm.getJp_up_m7()));
					footerMap1.put("jp_down_m7", (footerMap1.get("jp_down_m7")==null?forecastForm.getJp_down_m7():Float.parseFloat(footerMap1.get("jp_down_m7").toString())+forecastForm.getJp_down_m7()));
					
					footerMap1.put("zh_up_m8", (footerMap1.get("zh_up_m8")==null?forecastForm.getZh_down_m8():Float.parseFloat(footerMap1.get("zh_up_m8").toString())+forecastForm.getZh_up_m8()));
					footerMap1.put("zh_down_m8", (footerMap1.get("zh_down_m8")==null?forecastForm.getZh_down_m8():Float.parseFloat(footerMap1.get("zh_down_m8").toString())+forecastForm.getZh_down_m8()));
					footerMap1.put("jp_up_m8", (footerMap1.get("jp_up_m8")==null?forecastForm.getJp_up_m8():Float.parseFloat(footerMap1.get("jp_up_m8").toString())+forecastForm.getJp_up_m8()));
					footerMap1.put("jp_down_m8", (footerMap1.get("jp_down_m8")==null?forecastForm.getJp_down_m8():Float.parseFloat(footerMap1.get("jp_down_m8").toString())+forecastForm.getJp_down_m8()));
					
					footerMap1.put("zh_up_m9", (footerMap1.get("zh_up_m9")==null?forecastForm.getZh_down_m9():Float.parseFloat(footerMap1.get("zh_up_m9").toString())+forecastForm.getZh_up_m9()));
					footerMap1.put("zh_down_m9", (footerMap1.get("zh_down_m9")==null?forecastForm.getZh_down_m9():Float.parseFloat(footerMap1.get("zh_down_m9").toString())+forecastForm.getZh_down_m9()));
					footerMap1.put("jp_up_m9", (footerMap1.get("jp_up_m9")==null?forecastForm.getJp_up_m9():Float.parseFloat(footerMap1.get("jp_up_m9").toString())+forecastForm.getJp_up_m9()));
					footerMap1.put("jp_down_m9", (footerMap1.get("jp_down_m9")==null?forecastForm.getJp_down_m9():Float.parseFloat(footerMap1.get("jp_down_m9").toString())+forecastForm.getJp_down_m9()));
					
					footerMap1.put("zh_up_m10", (footerMap1.get("zh_up_m10")==null?forecastForm.getZh_down_m10():Float.parseFloat(footerMap1.get("zh_up_m10").toString())+forecastForm.getZh_up_m10()));
					footerMap1.put("zh_down_m10", (footerMap1.get("zh_down_m10")==null?forecastForm.getZh_down_m10():Float.parseFloat(footerMap1.get("zh_down_m10").toString())+forecastForm.getZh_down_m10()));
					footerMap1.put("jp_up_m10", (footerMap1.get("jp_up_m10")==null?forecastForm.getJp_up_m10():Float.parseFloat(footerMap1.get("jp_up_m10").toString())+forecastForm.getJp_up_m10()));
					footerMap1.put("jp_down_m10", (footerMap1.get("jp_down_m10")==null?forecastForm.getJp_down_m10():Float.parseFloat(footerMap1.get("jp_down_m10").toString())+forecastForm.getJp_down_m10()));
					
					footerMap1.put("zh_up_m11", (footerMap1.get("zh_up_m11")==null?forecastForm.getZh_down_m11():Float.parseFloat(footerMap1.get("zh_up_m11").toString())+forecastForm.getZh_up_m11()));
					footerMap1.put("zh_down_m11", (footerMap1.get("zh_down_m11")==null?forecastForm.getZh_down_m11():Float.parseFloat(footerMap1.get("zh_down_m11").toString())+forecastForm.getZh_down_m11()));
					footerMap1.put("jp_up_m11", (footerMap1.get("jp_up_m11")==null?forecastForm.getJp_up_m11():Float.parseFloat(footerMap1.get("jp_up_m11").toString())+forecastForm.getJp_up_m11()));
					footerMap1.put("jp_down_m11", (footerMap1.get("jp_down_m11")==null?forecastForm.getJp_down_m11():Float.parseFloat(footerMap1.get("jp_down_m11").toString())+forecastForm.getJp_down_m11()));
					
					footerMap1.put("zh_up_m12", (footerMap1.get("zh_up_m12")==null?forecastForm.getZh_down_m12():Float.parseFloat(footerMap1.get("zh_up_m12").toString())+forecastForm.getZh_up_m12()));
					footerMap1.put("zh_down_m12", (footerMap1.get("zh_down_m12")==null?forecastForm.getZh_down_m12():Float.parseFloat(footerMap1.get("zh_down_m12").toString())+forecastForm.getZh_down_m12()));
					footerMap1.put("jp_up_m12", (footerMap1.get("jp_up_m12")==null?forecastForm.getJp_up_m12():Float.parseFloat(footerMap1.get("jp_up_m12").toString())+forecastForm.getJp_up_m12()));
					footerMap1.put("jp_down_m12", (footerMap1.get("jp_down_m12")==null?forecastForm.getJp_down_m12():Float.parseFloat(footerMap1.get("jp_down_m12").toString())+forecastForm.getJp_down_m12()));
				}
				
				//合计
				footerMap2.put("zh_up_m1", (footerMap2.get("zh_up_m1")==null?forecastForm.getZh_up_m1():Float.parseFloat(footerMap2.get("zh_up_m1").toString())+forecastForm.getZh_up_m1()));
				footerMap2.put("zh_down_m1", (footerMap2.get("zh_down_m1")==null?forecastForm.getZh_down_m1():Float.parseFloat(footerMap2.get("zh_down_m1").toString())+forecastForm.getZh_down_m1()));
				footerMap2.put("jp_up_m1", (footerMap2.get("jp_up_m1")==null?forecastForm.getJp_up_m1():Float.parseFloat(footerMap2.get("jp_up_m1").toString())+forecastForm.getJp_up_m1()));
				footerMap2.put("jp_down_m1", (footerMap2.get("jp_down_m1")==null?forecastForm.getJp_down_m1():Float.parseFloat(footerMap2.get("jp_down_m1").toString())+forecastForm.getJp_down_m1()));
				
				footerMap2.put("zh_up_m2", (footerMap2.get("zh_up_m2")==null?forecastForm.getZh_up_m3():Float.parseFloat(footerMap2.get("zh_up_m2").toString())+forecastForm.getZh_up_m2()));
				footerMap2.put("zh_down_m2", (footerMap2.get("zh_down_m2")==null?forecastForm.getZh_down_m2():Float.parseFloat(footerMap2.get("zh_down_m2").toString())+forecastForm.getZh_down_m2()));
				footerMap2.put("jp_up_m2", (footerMap2.get("jp_up_m2")==null?forecastForm.getJp_up_m2():Float.parseFloat(footerMap2.get("jp_up_m2").toString())+forecastForm.getJp_up_m2()));
				footerMap2.put("jp_down_m2", (footerMap2.get("jp_down_m2")==null?forecastForm.getJp_down_m2():Float.parseFloat(footerMap2.get("jp_down_m2").toString())+forecastForm.getJp_down_m2()));
				
				footerMap2.put("zh_up_m3", (footerMap2.get("zh_up_m3")==null?forecastForm.getZh_up_m3():Float.parseFloat(footerMap2.get("zh_up_m3").toString())+forecastForm.getZh_up_m3()));
				footerMap2.put("zh_down_m3", (footerMap2.get("zh_down_m3")==null?forecastForm.getZh_down_m3():Float.parseFloat(footerMap2.get("zh_down_m3").toString())+forecastForm.getZh_down_m3()));
				footerMap2.put("jp_up_m3", (footerMap2.get("jp_up_m3")==null?forecastForm.getJp_up_m3():Float.parseFloat(footerMap2.get("jp_up_m3").toString())+forecastForm.getJp_up_m3()));
				footerMap2.put("jp_down_m3", (footerMap2.get("jp_down_m3")==null?forecastForm.getJp_down_m3():Float.parseFloat(footerMap2.get("jp_down_m3").toString())+forecastForm.getJp_down_m3()));
				
				footerMap2.put("zh_up_m4", (footerMap2.get("zh_up_m4")==null?forecastForm.getZh_up_m4():Float.parseFloat(footerMap2.get("zh_up_m4").toString())+forecastForm.getZh_up_m4()));
				footerMap2.put("zh_down_m4", (footerMap2.get("zh_down_m4")==null?forecastForm.getZh_down_m4():Float.parseFloat(footerMap2.get("zh_down_m4").toString())+forecastForm.getZh_down_m4()));
				footerMap2.put("jp_up_m4", (footerMap2.get("jp_up_m4")==null?forecastForm.getJp_up_m4():Float.parseFloat(footerMap2.get("jp_up_m4").toString())+forecastForm.getJp_up_m4()));
				footerMap2.put("jp_down_m4", (footerMap2.get("jp_down_m4")==null?forecastForm.getJp_down_m4():Float.parseFloat(footerMap2.get("jp_down_m4").toString())+forecastForm.getJp_down_m4()));
				
				footerMap2.put("zh_up_m5", (footerMap2.get("zh_up_m5")==null?forecastForm.getZh_up_m5():Float.parseFloat(footerMap2.get("zh_up_m5").toString())+forecastForm.getZh_up_m5()));
				footerMap2.put("zh_down_m5", (footerMap2.get("zh_down_m5")==null?forecastForm.getZh_down_m5():Float.parseFloat(footerMap2.get("zh_down_m5").toString())+forecastForm.getZh_down_m5()));
				footerMap2.put("jp_up_m5", (footerMap2.get("jp_up_m5")==null?forecastForm.getJp_up_m5():Float.parseFloat(footerMap2.get("jp_up_m5").toString())+forecastForm.getJp_up_m5()));
				footerMap2.put("jp_down_m5", (footerMap2.get("jp_down_m5")==null?forecastForm.getJp_down_m5():Float.parseFloat(footerMap2.get("jp_down_m5").toString())+forecastForm.getJp_down_m5()));
				
				footerMap2.put("zh_up_m6", (footerMap2.get("zh_up_m6")==null?forecastForm.getZh_up_m6():Float.parseFloat(footerMap2.get("zh_up_m6").toString())+forecastForm.getZh_up_m6()));
				footerMap2.put("zh_down_m6", (footerMap2.get("zh_down_m6")==null?forecastForm.getZh_down_m6():Float.parseFloat(footerMap2.get("zh_down_m6").toString())+forecastForm.getZh_down_m6()));
				footerMap2.put("jp_up_m6", (footerMap2.get("jp_up_m6")==null?forecastForm.getJp_up_m6():Float.parseFloat(footerMap2.get("jp_up_m6").toString())+forecastForm.getJp_up_m6()));
				footerMap2.put("jp_down_m6", (footerMap2.get("jp_down_m6")==null?forecastForm.getJp_down_m6():Float.parseFloat(footerMap2.get("jp_down_m6").toString())+forecastForm.getJp_down_m6()));
				
				footerMap2.put("zh_up_m7", (footerMap2.get("zh_up_m7")==null?forecastForm.getZh_up_m7():Float.parseFloat(footerMap2.get("zh_up_m7").toString())+forecastForm.getZh_up_m7()));
				footerMap2.put("zh_down_m7", (footerMap2.get("zh_down_m7")==null?forecastForm.getZh_down_m7():Float.parseFloat(footerMap2.get("zh_down_m7").toString())+forecastForm.getZh_down_m7()));
				footerMap2.put("jp_up_m7", (footerMap2.get("jp_up_m7")==null?forecastForm.getJp_up_m7():Float.parseFloat(footerMap2.get("jp_up_m7").toString())+forecastForm.getJp_up_m7()));
				footerMap2.put("jp_down_m7", (footerMap2.get("jp_down_m7")==null?forecastForm.getJp_down_m7():Float.parseFloat(footerMap2.get("jp_down_m7").toString())+forecastForm.getJp_down_m7()));
				
				footerMap2.put("zh_up_m8", (footerMap2.get("zh_up_m8")==null?forecastForm.getZh_up_m8():Float.parseFloat(footerMap2.get("zh_up_m8").toString())+forecastForm.getZh_up_m8()));
				footerMap2.put("zh_down_m8", (footerMap2.get("zh_down_m8")==null?forecastForm.getZh_down_m8():Float.parseFloat(footerMap2.get("zh_down_m8").toString())+forecastForm.getZh_down_m8()));
				footerMap2.put("jp_up_m8", (footerMap2.get("jp_up_m8")==null?forecastForm.getJp_up_m8():Float.parseFloat(footerMap2.get("jp_up_m8").toString())+forecastForm.getJp_up_m8()));
				footerMap2.put("jp_down_m8", (footerMap2.get("jp_down_m8")==null?forecastForm.getJp_down_m8():Float.parseFloat(footerMap2.get("jp_down_m8").toString())+forecastForm.getJp_down_m8()));
				
				footerMap2.put("zh_up_m9", (footerMap2.get("zh_up_m9")==null?forecastForm.getZh_up_m9():Float.parseFloat(footerMap2.get("zh_up_m9").toString())+forecastForm.getZh_up_m9()));
				footerMap2.put("zh_down_m9", (footerMap2.get("zh_down_m9")==null?forecastForm.getZh_down_m9():Float.parseFloat(footerMap2.get("zh_down_m9").toString())+forecastForm.getZh_down_m9()));
				footerMap2.put("jp_up_m9", (footerMap2.get("jp_up_m9")==null?forecastForm.getJp_up_m9():Float.parseFloat(footerMap2.get("jp_up_m9").toString())+forecastForm.getJp_up_m9()));
				footerMap2.put("jp_down_m9", (footerMap2.get("jp_down_m9")==null?forecastForm.getJp_down_m9():Float.parseFloat(footerMap2.get("jp_down_m9").toString())+forecastForm.getJp_down_m9()));
				
				footerMap2.put("zh_up_m10", (footerMap2.get("zh_up_m10")==null?forecastForm.getZh_up_m10():Float.parseFloat(footerMap2.get("zh_up_m10").toString())+forecastForm.getZh_up_m10()));
				footerMap2.put("zh_down_m10", (footerMap2.get("zh_down_m10")==null?forecastForm.getZh_down_m10():Float.parseFloat(footerMap2.get("zh_down_m10").toString())+forecastForm.getZh_down_m10()));
				footerMap2.put("jp_up_m10", (footerMap2.get("jp_up_m10")==null?forecastForm.getJp_up_m10():Float.parseFloat(footerMap2.get("jp_up_m10").toString())+forecastForm.getJp_up_m10()));
				footerMap2.put("jp_down_m10", (footerMap2.get("jp_down_m10")==null?forecastForm.getJp_down_m10():Float.parseFloat(footerMap2.get("jp_down_m10").toString())+forecastForm.getJp_down_m10()));
				
				footerMap2.put("zh_up_m11", (footerMap2.get("zh_up_m11")==null?forecastForm.getZh_up_m11():Float.parseFloat(footerMap2.get("zh_up_m11").toString())+forecastForm.getZh_up_m11()));
				footerMap2.put("zh_down_m11", (footerMap2.get("zh_down_m11")==null?forecastForm.getZh_down_m11():Float.parseFloat(footerMap2.get("zh_down_m11").toString())+forecastForm.getZh_down_m11()));
				footerMap2.put("jp_up_m11", (footerMap2.get("jp_up_m11")==null?forecastForm.getJp_up_m11():Float.parseFloat(footerMap2.get("jp_up_m11").toString())+forecastForm.getJp_up_m11()));
				footerMap2.put("jp_down_m11", (footerMap2.get("jp_down_m11")==null?forecastForm.getJp_down_m11():Float.parseFloat(footerMap2.get("jp_down_m11").toString())+forecastForm.getJp_down_m11()));
				
				footerMap2.put("zh_up_m12", (footerMap2.get("zh_up_m12")==null?forecastForm.getZh_up_m12():Float.parseFloat(footerMap2.get("zh_up_m12").toString())+forecastForm.getZh_up_m12()));
				footerMap2.put("zh_down_m12", (footerMap2.get("zh_down_m12")==null?forecastForm.getZh_down_m12():Float.parseFloat(footerMap2.get("zh_down_m12").toString())+forecastForm.getZh_down_m12()));
				footerMap2.put("jp_up_m12", (footerMap2.get("jp_up_m12")==null?forecastForm.getJp_up_m12():Float.parseFloat(footerMap2.get("jp_up_m12").toString())+forecastForm.getJp_up_m12()));
				footerMap2.put("jp_down_m12", (footerMap2.get("jp_down_m12")==null?forecastForm.getJp_down_m12():Float.parseFloat(footerMap2.get("jp_down_m12").toString())+forecastForm.getJp_down_m12()));
				
				
				
			}
			
			
			//上旬
			footerMap3.put("zh_up_m1", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m1").toString()) + Float.parseFloat(footerMap2.get("jp_up_m1").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m2", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m2").toString()) + Float.parseFloat(footerMap2.get("jp_up_m2").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m3", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m3").toString()) + Float.parseFloat(footerMap2.get("jp_up_m3").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m4", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m4").toString()) + Float.parseFloat(footerMap2.get("jp_up_m4").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m5", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m5").toString()) + Float.parseFloat(footerMap2.get("jp_up_m5").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m6", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m6").toString()) + Float.parseFloat(footerMap2.get("jp_up_m6").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m7", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m7").toString()) + Float.parseFloat(footerMap2.get("jp_up_m7").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m8", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m8").toString()) + Float.parseFloat(footerMap2.get("jp_up_m8").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m9", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m9").toString()) + Float.parseFloat(footerMap2.get("jp_up_m9").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m10", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m10").toString()) + Float.parseFloat(footerMap2.get("jp_up_m10").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m11", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m11").toString()) + Float.parseFloat(footerMap2.get("jp_up_m11").toString()))).intValue())+"</b>");
			footerMap3.put("zh_up_m12", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_up_m12").toString()) + Float.parseFloat(footerMap2.get("jp_up_m12").toString()))).intValue())+"</b>");
			//下旬
			footerMap4.put("zh_up_m1", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m1").toString()) + Float.parseFloat(footerMap2.get("jp_down_m1").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m2", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m2").toString()) + Float.parseFloat(footerMap2.get("jp_down_m2").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m3", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m3").toString()) + Float.parseFloat(footerMap2.get("jp_down_m3").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m4", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m4").toString()) + Float.parseFloat(footerMap2.get("jp_down_m4").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m5", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m5").toString()) + Float.parseFloat(footerMap2.get("jp_down_m5").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m6", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m6").toString()) + Float.parseFloat(footerMap2.get("jp_down_m6").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m7", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m7").toString()) + Float.parseFloat(footerMap2.get("jp_down_m7").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m8", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m8").toString()) + Float.parseFloat(footerMap2.get("jp_down_m8").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m9", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m9").toString()) + Float.parseFloat(footerMap2.get("jp_down_m9").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m10", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m10").toString()) + Float.parseFloat(footerMap2.get("jp_down_m10").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m11", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m11").toString()) + Float.parseFloat(footerMap2.get("jp_down_m11").toString()))).intValue())+"</b>");
			footerMap4.put("zh_up_m12", "<b class=\"cols4\">"+(((Float)(Float.parseFloat(footerMap2.get("zh_down_m12").toString()) + Float.parseFloat(footerMap2.get("jp_down_m12").toString()))).intValue())+"</b>");
			
			
			//表格页脚
			footers.add(footerMap1) ;
			footers.add(footerMap2) ;
			footers.add(footerMap3) ;
			footers.add(footerMap4) ;
		}
		
		
		DataGrid dg = new DataGrid() ;
		dg.setRows(findList);
		dg.setFooter(footers);
		return dg;
	}
	
	
	
	@Override
	public DataGrid getDeptOwnerList(ForecastForm form) {
		return this.redure(this.findList(form)) ;
	}

	@Override
	public DataGrid getAllDeptOwnerList(ForecastForm form) {
		return this.redure(this.findList(form)) ;
	}
	
	@Override
	public DataGrid datagrid(ForecastForm form) {
		List<ForecastForm> forms = new ArrayList<ForecastForm>() ;
		Pager<ForecastForm> pager = this.findPage(form) ;
		if (null != pager && !pager.getDataRows().isEmpty()) {
			for(ForecastForm pf : pager.getDataRows()) {
				forms.add(pf) ;
			}
		}
		
		DataGrid dg = new DataGrid() ;
		dg.setTotal(pager.getTotal());
		dg.setRows(forms);
		return dg;
	}
	
	
	
	List<ForecastForm> findListGroup(ForecastForm form) {
		Map<String, Object> alias = new HashMap<String, Object>();
		String sql = "select " +
				"t.*, "
				+ "ty.jp_down_m1,ty.jp_down_m10,ty.jp_down_m11,ty.jp_down_m12,ty.jp_down_m2,ty.jp_down_m3,"
				+ "ty.jp_down_m4,ty.jp_down_m5,ty.jp_down_m6,ty.jp_down_m7,ty.jp_down_m8,ty.jp_down_m9,"
				+ "ty.jp_up_m1,ty.jp_up_m10,ty.jp_up_m11,ty.jp_up_m12,ty.jp_up_m2,ty.jp_up_m3,ty.jp_up_m4,"
				+ "ty.jp_up_m5,ty.jp_up_m6,ty.jp_up_m7,ty.jp_up_m8,ty.jp_up_m9,ty.zh_down_m1,ty.zh_down_m10,"
				+ "ty.zh_down_m11,ty.zh_down_m12,ty.zh_down_m2,ty.zh_down_m3,ty.zh_down_m4,ty.zh_down_m5,ty."
				+ "zh_down_m6,ty.zh_down_m7,ty.zh_down_m8,ty.zh_down_m9,ty.zh_up_m1,ty.zh_up_m10,ty.zh_up_m11,"
				+ "ty.zh_up_m12,ty.zh_up_m2,ty.zh_up_m3,ty.zh_up_m4,ty.zh_up_m5,ty.zh_up_m6,ty.zh_up_m7,ty.zh_up_m8,ty.zh_up_m9 "+
				"from ieasy_oa_forecast t " +
				"JOIN ieasy_oa_forecast_year ty ON(ty.forecastId=t.id) " +
				"where 1=1 ";
		sql = addWhere(sql, form, alias) ;
		
		return this.basedaoForecast.listSQL(sql, alias, ForecastForm.class, false) ;
	}
	
	List<ForecastForm> findList(ForecastForm form) {
		Map<String, Object> alias = new HashMap<String, Object>();
		String sql = "select " +
					 "t.*, "
					 + "ty.jp_down_m1,ty.jp_down_m10,ty.jp_down_m11,ty.jp_down_m12,ty.jp_down_m2,ty.jp_down_m3,"
					 + "ty.jp_down_m4,ty.jp_down_m5,ty.jp_down_m6,ty.jp_down_m7,ty.jp_down_m8,ty.jp_down_m9,"
					 + "ty.jp_up_m1,ty.jp_up_m10,ty.jp_up_m11,ty.jp_up_m12,ty.jp_up_m2,ty.jp_up_m3,ty.jp_up_m4,"
					 + "ty.jp_up_m5,ty.jp_up_m6,ty.jp_up_m7,ty.jp_up_m8,ty.jp_up_m9,ty.zh_down_m1,ty.zh_down_m10,"
					 + "ty.zh_down_m11,ty.zh_down_m12,ty.zh_down_m2,ty.zh_down_m3,ty.zh_down_m4,ty.zh_down_m5,ty."
					 + "zh_down_m6,ty.zh_down_m7,ty.zh_down_m8,ty.zh_down_m9,ty.zh_up_m1,ty.zh_up_m10,ty.zh_up_m11,"
					 + "ty.zh_up_m12,ty.zh_up_m2,ty.zh_up_m3,ty.zh_up_m4,ty.zh_up_m5,ty.zh_up_m6,ty.zh_up_m7,ty.zh_up_m8,ty.zh_up_m9 "+
					 "from ieasy_oa_forecast t " +
					 "JOIN ieasy_oa_forecast_year ty ON(ty.forecastId=t.id) " +
				 	 "where 1=1 ";
		sql = addWhere(sql, form, alias) ;
		
		return this.basedaoForecast.listSQL(sql, alias, ForecastForm.class, false) ;
	}
	
	Pager<ForecastForm> findPage(ForecastForm form) {
		Map<String, Object> alias = new HashMap<String, Object>();
		String sql = "select " +
					 "t.*, "
					 + "ty.jp_down_m1,ty.jp_down_m10,ty.jp_down_m11,ty.jp_down_m12,ty.jp_down_m2,ty.jp_down_m3,"
					 + "ty.jp_down_m4,ty.jp_down_m5,ty.jp_down_m6,ty.jp_down_m7,ty.jp_down_m8,ty.jp_down_m9,"
					 + "ty.jp_up_m1,ty.jp_up_m10,ty.jp_up_m11,ty.jp_up_m12,ty.jp_up_m2,ty.jp_up_m3,ty.jp_up_m4,"
					 + "ty.jp_up_m5,ty.jp_up_m6,ty.jp_up_m7,ty.jp_up_m8,ty.jp_up_m9,ty.zh_down_m1,ty.zh_down_m10,"
					 + "ty.zh_down_m11,ty.zh_down_m12,ty.zh_down_m2,ty.zh_down_m3,ty.zh_down_m4,ty.zh_down_m5,ty."
					 + "zh_down_m6,ty.zh_down_m7,ty.zh_down_m8,ty.zh_down_m9,ty.zh_up_m1,ty.zh_up_m10,ty.zh_up_m11,"
					 + "ty.zh_up_m12,ty.zh_up_m2,ty.zh_up_m3,ty.zh_up_m4,ty.zh_up_m5,ty.zh_up_m6,ty.zh_up_m7,ty.zh_up_m8,ty.zh_up_m9 "+
					 "from ieasy_oa_forecast t " +
					 "left JOIN ieasy_oa_forecast_year ty ON(ty.forecastId=t.id and ty.year=t.year) " +
				 	 "where 1=1 ";
		sql = addWhere(sql, form, alias) ;
		
		return this.basedaoForecast.findSQL(sql, alias, ForecastForm.class, false) ;
	}
	
	String addWhere(String sql, ForecastForm form, Map<String, Object> params) {
		if (null != form) {
			if (form.getPersonId() != null && !"".equals(form.getPersonId().trim())) {
				sql += " and t.personId =:personId";
				params.put("personId", form.getPersonId().trim());
			}
			if (form.getProjDeptId() != null && !"".equals(form.getProjDeptId().trim())) {
				sql += " and t.projDeptId =:projDeptId";
				params.put("projDeptId", form.getProjDeptId().trim());
			}
			if (form.getProjOver() != null && !"".equals(form.getProjOver().trim())) {
				sql += " and t.projOver =:projOver";
				params.put("projOver", form.getProjOver().trim());
			}
			if (form.getProjDegree() != null) {
				sql += " and t.projDegree =:projDegree";
				params.put("projDegree", form.getProjDegree());
			}
			if (form.getProjStatus() != null && !"".equals(form.getProjStatus().trim())) {
				sql += " and t.projStatus =:projStatus";
				params.put("projStatus", form.getProjStatus().trim());
			}
			if (form.getCustCategory() != null && !"".equals(form.getCustCategory().trim())) {
				sql += " and t.custCategory =:custCategory";
				params.put("custCategory", form.getCustCategory().trim());
			}
			
			sql += " and ty.year =:year order by t.projDeptName ";
			params.put("year", form.getYear());
			
		}
		return sql ;
	}

	@Override
	public List<ForecastForm> getCustCategory() {
		String sql = "select " +
				 "t.custCategory as text " +
				 "from ieasy_oa_forecast t " +
			 	 "group by t.custCategory";
		
		return this.basedaoForecast.listSQL(sql, ForecastForm.class, false) ;
	}
	
	
	
}
